<template>
  <div class="app-container">
    <block v-if="showPage">
      <div class="filter-container">
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-refresh" @click="reload">
          刷新
        </el-button>
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getDataList">
          查询
        </el-button>
      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData"
        border
        fit
        highlight-current-row
        style="width: 100%;"
      >
        <el-table-column label="序号" type="index" width="50px"/>
        <el-table-column label="渠道名称" align="center" prop="channelName"/>
        <el-table-column label="记录时间" align="center" prop="recordDate">
          <template slot-scope="scope">
            {{ scope.row.recordDate[0] }}-{{ scope.row.recordDate[1] }}-{{ scope.row.recordDate[2] }}
          </template>
        </el-table-column>
        <el-table-column label="注册数" align="center" prop="regNum"/>
      </el-table>
    </block>
    
    <el-dialog 
      :visible.sync="dialogFormVisible" 
      center 
      :close-on-click-modal="false" 
      :close-on-press-escape="false" 
      :show-close="false"
    >
      <div class="title">安信借钱后台管理系统<br/>分享已加密，请输入提取码进入网页</div>
      <el-input
        placeholder="请输入提取码"
        v-model="codes"
        clearable>
      </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getData" style="width: 100%;">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { checkExtractionCode,aesData } from '@/api/channel'
import waves from '@/directive/waves' // waves directive
export default {
  name: 'Phonelist',
  directives: { waves },
  data() {
    return {
      codes: '',
      listLoading: false,
      tableData: [],
      dialogFormVisible: true,
      showPage: false
    }
  },
  created() { 
  },
  methods: {
    getData(){
      if( this.codes == '' ){
        this.$message.error('请输入提取码');
        return false
      }
      checkExtractionCode({
        encodeId: this.$route.query.encodeId,
        extractionCode: this.codes
      }).then( res => {
        if( res.data.code == '200' ){
          
          if( res.data.data ){
            this.dialogFormVisible = false
            this.showPage = true
            this.getDataList()
          } else {
            this.showPage = false
            this.$message.error('无权查看');
          }
          
        }  else {
          this.$message.error(res.data.msg);
          return false
        }
      })
    },
    getDataList(){
      this.listLoading = true
      aesData({
        encodeId: this.$route.query.encodeId,
        extractionCode: this.codes
      }).then( res => {
        this.listLoading = false
        if( res.data.code == '200' ){
          this.tableData = res.data.data
        }  else {
          this.$message.error(res.data.msg);
        }
      })
    },
    reload(){
      window.location.reload()
    }
  }
}
</script>

<style scoped>
.title {
  text-align: center;
  line-height: 36px;
  font-size: 20px;
  flex-wrap: 700;
  padding-bottom: 15px;
}
</style>
